﻿#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
using namespace std;

class Test
{
	//如果没有写就默认是private
public:
	//成员函数
	void func1()
	{
		cout << "void func1()" << endl;
	}
	void func2()
	{
		cout << "void func2()" << endl;
	}
	//成员变量
//private:
	int _a;
	int _b;
};


struct Test2
{
	//成员函数
	void func1()
	{
		cout << "void func1()" << endl;
	}
	void func2()
	{
		cout << "void func2()" << endl;
	}
	//成员变量
	int _a;
	int _b;
};

//C需要typedef
typedef struct ListNodeC
{
	int val;
	struct ListNodeC* next;
}LTNode;

//而C++的类名就表示类型
struct ListNodeCpp
{
	void Init(int x)
	{
		val = x;
		next = nullptr;
	}
	int val;
	ListNodeCpp* next;
};

class Stack
{
public:
	//成员函数声明
	void Init(int n);

private:
	int* _arr;
	int _capacity;
	int _top;
};

//声明和定义分离需要指定类域
void Stack::Init(int n)
{
	_arr = (int*)malloc(sizeof(int) * n);
	if (_arr == nullptr)
	{
		perror("malloc fail!\n");
		return;
	}
	_capacity = n;
	_top = 0;
}

int main1()
{
	Stack st;
	st.Init(4);
	return 0;
}


class Data
{
public:
	void Init(int year, int month, int day)
	{
		_year = year;
		_month = month;
		_day = day;
	}
	void Print()
	{
		cout << _year << "/" << _month << "/" << _day << endl;
	}

private:
	//这里只是声明，并没有开空间
	int _year;
	int _month;
	int _day;
};

int main2()
{
	//用data类型实例化俩个对象d1,d2
	Data d1;
	Data d2;
	d1.Init(2024, 7, 18);
	d2.Init(2024, 7, 19);
	d1.Print();
	d2.Print();
	return 0;
}
// 计算⼀下A/B/C实例化的对象是多⼤？
class A
{
public:
	void Print()
	{
		cout << _ch << endl;
	}
private:
	char _ch;
	int _i;
};
class B
{
public:
	void Print()
	{
		//...
	}
};
class C
{};
int main()
{
	A a;
	B b;
	C c;
	cout << sizeof(a) << endl;
	cout << sizeof(b) << endl;
	cout << sizeof(c) << endl;
	return 0;
}
